package b2.scene.fight.skills
{
	import b2.config.*;
	import b2.scene.fight.*;
	
	import flash.geom.Point;
	
	public class Resurrect extends BasicSkill
	{
		public function Resurrect(tankId:int, tankSide:int, level:int, skillArgs:Object)
		{
			super(tankId, tankSide, level, skillArgs);
		}
		
		public override function checkSkillTriggerPremise(x:int, y:int, direction:int):Boolean
		{
			var tank:TankSprite = getPlayState().tanks[tankId];
			if (coolDown < 0)
			{
				var message:String = "<font color='#0000FF'>" + tank.tankName + "</font>发动了<font color='#FF0000'>" + skillArgs.name + "</font>";
				FightScene.getInstance().showBottomMessage(message);
				tank.showMessageFlag = false;
				return true;
			}
			else if (!tank.showMessageFlag && coolDown == 6)
			{
				message = "<font color='#0000FF'>" + tank.tankName + "</font><font color='#00AA00'> 5 </font>秒后发动<font color='#FF0000'>" 
							+ skillArgs.name + "</font>"
				FightScene.getInstance().showTopMessage(message);
				tank.showMessageFlag = true;
				return false;
			}
			return false;
		}
		
		public override function discharge(x:int, y:int, direction:int):void
		{
			var tankCount:Object = new Object();
			for (var tankIdStr:String in getPlayState().tanks)
			{
				var tankSprite:TankSprite = getPlayState().tanks[tankIdStr];
				if (tankSprite.side == this.side)
				{
					if (tankCount[tankSprite.enemyIndex] == null)
						tankCount[tankSprite.enemyIndex] = 1;
					else
						tankCount[tankSprite.enemyIndex]++;
				}
			}
			for (var i:int = 0; i < skillArgs.effectValue.length; i++)
			{
				var enemyIndex:int = skillArgs.effectValue[i];
				var expectCount:int = skillArgs.effectValue2[i];
				var existCount:int = tankCount[enemyIndex] == null ? 0 : tankCount[enemyIndex];
				for (var j:int = 0; j < expectCount - existCount; j++)
				{
					//复活坦克
					var enemyConfig:EnemyConfig = Config.enemyConfigs[enemyIndex];
					var tankId:int = -int.MAX_VALUE * Math.random();
					var direction:int = Math.random() * 4;
					var randPos:Point = getPlayState().getRandEmptyPos(); 
					var posX:int = randPos.x;
					var posY:int = randPos.y;
					var level:int = this.level;
					var bossLevel:int = 0;
					getPlayState().createTank(tankId, enemyConfig.tankIndex, enemyConfig.name, TankSprite.SIDE_COMP, direction, PlayState.OFFSET_X + PlayState.TILE_WIDTH * posX, PlayState.OFFSET_Y + PlayState.TILE_WIDTH * posY, 
						enemyConfig.healthPoint * level + enemyConfig.healthPoint * level * bossLevel * 3, 
						enemyConfig.energyPoint * level, enemyConfig.attackPoint * level, 
						enemyConfig.criticalAttackRatio * level, enemyConfig.armPoint * level, enemyConfig.moveVelocity, 
						enemyConfig.fireCooldown, enemyConfig.index, level, bossLevel);
					var message:String = "<font color='#0000FF'>" + enemyConfig.name + "</font>被复活了";
					FightScene.getInstance().showBottomMessage(message);
				}
			}
			super.discharge(x, y, direction);
		}
	}
}